<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model common\models\Exhibition */

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'exhibition'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<?=Html::jsFile('/static/common/js/Chart.min.js')?>
<style>
    .exhibition-view img {
        max-width: 100%;
    }
    .chart {
        width: 400px;
        height: 210px;
    }
</style>
<div class="exhibition-view">

    <p>
        <?= Html::a(Yii::t('common', 'update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
        <?= Html::a(Yii::t('common', 'delete'), ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => Yii::t('common', 'are_you_sure_you_want_to_delete_this_item?'),
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            //'id',
            'title',
            [
                'attribute' => 'category_id',
                'value' => \common\models\ExhibitionCategory::getExhibitionCategoryName($model->category_id),
            ],
            'hall_title',
            'logo:image',
            'litpic:image',
            'bg:image',
            [
                'attribute' => 'recommend',
                'value' => \common\helpers\TStringHelper::getYesOrNo($model->recommend),
            ],
            'starttime:datetime',
            'endtime:datetime',
            'city',
            'area',
            'website:url',
            'address',
            [
                'attribute' => 'hot',
                'value' => \common\helpers\TStringHelper::getExhibitionHotRank($model->hot),
            ],
            'wechat_qrcode:image',
            'video',
            [
                'attribute' => 'recommend',
                'value' => \common\helpers\TStringHelper::getYesOrNo($model->recommend),
            ],
            'business_number',
            [
                'label' => Yii::t('common', 'exhibition_business'),
                'value' => '<div class="chart" id="pieChartBusiness"></div>',
                'format' => 'raw'
            ],
            'audience_number',
            [
                'label' => Yii::t('common', 'exhibition_audience'),
                'value' => '<div class="chart" id="pieChartAudience"></div>',
                'format' => 'raw'
            ],
            'comments_number',
            'score',
            'follow_number',
            [
                'attribute' => 'status',
                'value' => \common\helpers\TStringHelper::getStatusText($model->status),
            ],
            'order',
            'tags',
            'introduce:html',
            'scope:html',
            'booth_info:html',
            'sponsor:html',
            'undertook:html',
        ],
        'template' => '<tr><th width="100px">{label}</th><td>{value}</td></tr>',
    ]) ?>

</div>

<script>
/**
 * 获取ajax页面
 * @param url
 * @param div
 * @param data
 */
function getAjaxPage(url, data, div){
    $("#"+div).html('<p>数据加载中，请稍后...</p>');
    $.get(url, data, function(txt) {
        $("#"+div).html(txt);
    })
}
    getAjaxPage('<?=Yii::$app->urlManager->createUrl(['/../zhanhui/get-business', 'exhibition_id' => $model->id])?>', {}, 'pieChartBusiness');
    getAjaxPage('<?=Yii::$app->urlManager->createUrl(['/../zhanhui/get-audience', 'exhibition_id' => $model->id])?>', {}, 'pieChartAudience');
</script>
